<template>
  <div class="content">
    <img :src="getParams.qrcodeUrl" alt="" />
    <div>bid:{{ bid }}</div>
    <div>phone:{{ phone }}</div>
    <div>sid:{{ sid }}</div>
    <div>reffer:{{ reffer }}</div>
    <div>traceId:{{ traceId }}</div>
    <div>{{ url }}</div>
  </div>
</template>

<script>
import { get, post } from "../api/axios";
import { getSign, getAllParams } from "../assets/utils";

export default {
  name: "Demo3Successpage",

  data() {
    return {
      url: window.location.href,
      getParams: {}, //一客一码的参数
    };
  },

  computed: {
    bid() {
      return this.$route.query.bid || "";
    },
    sid() {
      return this.$route.query.sid || "";
    },
    reffer() {
      return this.$route.query.reffer || "";
    },
    phone() {
      return this.$route.query.phone || "";
    },
    traceId() {
      return this.$route.query.traceId || "";
    },
  },

  async created() {
    // 通用回传+神策统计
    this.callbackFun("in_applet");
    const res = await get(
      "https://data-platform.qh5800.com/api/2/h5/qq/dispatch.json?bid=3512414"
    );
    this.getParams = res.data;
    // 预约头像二维码
    const res2 = await post(
      "/h5/openApi/v1.0/webox/corp/internal/prebuild/contactCode",
      {
        corpId: this.getParams.qyCode,
        bizMobile: this.getParams.mobilePhone,
        mobile: this.phone,
        sid: this.sid,
        bid: this.bid,
        reffer: this.reffer,
      },
      {
        headers: {
          "Content-Type": "application/json",
          serverId: 10011218,
          sign: 123123,
        },
      }
    );

    // 兑换头像二维码
    const res3 = await post(
      "/h5/openApi/v1.0/webox/corp/internal/exchange/contactCode",
      {
        corpId: this.getParams.qyCode,
        bizMobile: this.getParams.mobilePhone,
        mobile: this.phone,
        sid: this.sid,
        bid: this.bid,
        reffer: this.reffer,
      },
      {
        headers: {
          "Content-Type": "application/json",
          serverId: 10011218,
          sign: 123123,
        },
      }
    );
  },

  mounted() {
    this.callbackFun("in_applet");
  },

  methods: {
    // 通用回传
    async callbackFun(event) {
      let params = {
        eventType: event,
        reffer: this.reffer,
        sid: this.sid,
        bid: this.bid,
        traceId: this.traceId,
      };
      let headers = {
        serverId: 10011218,
        sign: getSign(params, this),
      };
      const res2 = await post(
        "/h5/openApi/v1.0/market-extension/event/common/callback",
        params,
        { headers }
      );
      console.log(res2);
    },
  },
};
</script>

<style lang="less" scoped>
.content {
  width: 100%;
  height: 1000px;
  text-align: center;
  position: absolute;
  bottom: 0;
  font-size: 40px;
  img {
    width: 100%;
  }
  div {
    width: 100%;
  }
}
</style>
